# -*- coding: utf-8 -*-

from scrapy import cmdline
from scrapy.spiders import CrawlSpider
import scrapy
from astropy.io.fits.header import Header

import  requests


class ZhihuUserSpider(CrawlSpider):
    name = "zhihu_user"
    allowed_domains = ['zhihu.com']
    start_urls = ["http://www.zhihu.com"]
    headers = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'
    }

    def start_requests(self):     # 登陆
        return [scrapy.FormRequest.from_response(
            "http://www.zhihu.com/login/phone_num",

            formdata={
                '_xsrf':'7ecec739ea7f9e42d3a605e2c44883d3',
                'remember_me':'true',
                'password':'******',
                'phone_num':'******'
            },
            headers=self.headers,
            # cookies = self.cook,

            callback=self.after_login,

        )]

    def after_login(self, response):
        print('after login')
        yield scrapy.Request('https://www.zhihu.com/people/shuangyueliao-82/activities',callback=self.onetwo,headers=self.headers)

    def onetwo(self,response):
        print(response.body)


if __name__ == '__main__':
    scrapy.cmdline.execute(argv=['scrapy','scrapy.spiders.crawl','zhihu_user'])


requests.get()
